define(['jquery'], () => {
    class Footer {
      constructor () {
        this.load().then(() => {
          this. calcCartNum()
          // 执行加载成功之后的逻辑
          // this.search()
        })
      }
  
      // 加载尾部html
      load () {
        return new Promise(resolve => {
          // 加载成功之后resolve
          $('footer').load('/html/modules/footer.html', resolve)
        })
      }
      calcCartNum(){
        let cartList=localStorage.getItem('cart')
        if(cartList){
          cartList=JSON.parse(cartList)
          let num=cartList.reduce((total,cart)=>{
             total +=cart.num
             return total
          },0)
          $('#shopnum').html(num)
        }else{
          $('#shopnum').html(0)
        }
      }
    }
    return new Footer()
});
